package org.example.controller;


import org.example.entity.LoginDTO;
import org.example.entity.ResponseModel;
import org.example.service.LoginService;
import org.example.service.LogoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {


    @Autowired
    private LoginService loginService;


    @Autowired
    private LogoutService logoutService;

    @PostMapping("/login")
    public ResponseModel<String> login(@RequestBody LoginDTO dto)
    {
        try {
            return loginService.checkLogin(dto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseModel.authFailure("认证失败"+e.getMessage());
        }

    }

    @GetMapping("/logout")
    public ResponseModel<String> logout()
    {
        return logoutService.logout();
    }



}
